package com.test.io;

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class SocketDemo {
    public static void main(String[] args) throws  Exception{
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.configureBlocking(false);
        socketChannel.connect(new InetSocketAddress("http://jenkov.com", 80));
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        while (!socketChannel.finishConnect()){
            int byteReader = socketChannel.read(buffer);
            while (byteReader!=-1) {
                buffer.flip();
                System.out.println(buffer.get());
                buffer.clear();
                byteReader = socketChannel.read(buffer);
            }
        }
        socketChannel.close();
    }
}
